package com.blb.controller;

import com.blb.pojo.News;
import com.blb.service.NewsService;
import com.blb.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author 祖星毅
 */
@RestController
@CrossOrigin(origins = "*")
@Api(tags = "集团新闻")
public class NewsController {
    @Autowired
    private NewsService newsService;

    /**
     * 分页查找新闻表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "分页查询集团新闻")
    @GetMapping("/news")
    public Page get(@ApiParam(name = "pageNum",value = "当前页",required = true)
                        @RequestParam(value = "pageNum",defaultValue = "1",required = true) Integer pageNum,
                    @ApiParam(name = "pageSize",value = "每页数量",required = true)
                    @RequestParam(value = "pageSize",defaultValue = "5",required = true) Integer pageSize) {
        return newsService.selectByPage(pageNum, pageSize);
    }

    /**
     * 新闻表通过主键id查找
     * @param id
     * @return
     */
    @GetMapping("/news/{id}")
    @ApiOperation(value = "根据id查询集团新闻")
    public News get(@ApiParam(name = "id",value = "新闻id",required = true)
                        @PathVariable Integer id) {
        return newsService.selectByPrimaryKey(id);
    }

}
